import vine from '@vinejs/vine'
import type { Infer } from '@vinejs/vine/types'

export const createDictSchema = vine.object({
  name: vine.string().maxLength(50),
  className: vine.enum(['role', 'payment', 'category', 'post', 'dept', 'source']),
  sort: vine.number().positive().optional(),
  code: vine.string().maxLength(20),
  extra: vine.record(vine.any()).optional(),
  memo: vine.string().maxLength(255).optional(),
})

export type CreateDictSchema = Infer<typeof createDictSchema>

export const createDictValidator = vine.compile(createDictSchema)

const updateSchema = vine.object({
  name: vine.string().maxLength(50).optional(),
  sort: vine.number().positive().optional(),
  code: vine.string().maxLength(20).optional(),
  extra: vine.record(vine.any()).optional(),
  memo: vine.string().maxLength(255).optional(),
})
export type UpdateDictSchema = Infer<typeof updateSchema>

export const updateDictValidator = vine.compile(updateSchema)
